package com.ruanmou.vip.rabbitmq.demo.wq.fair;

import com.rabbitmq.client.Channel;
import com.ruanmou.vip.rabbitmq.demo.util.RabbitMQUtil;

import java.util.concurrent.TimeUnit;

/**
 * 欢迎同学们来到牧码人教育
 *
 * @Classname Producer
 * @Description TODO
 * @Date 2020-3-7 10:49
 * @Created by Gerry
 */
public class WQProducer {

    public static void main(String[] args) throws Exception {
        // 创建Channel
        Channel channel = RabbitMQUtil.getConnection().createChannel();
        // 定义一个队列
        channel.queueDeclare("wq_queue1",false,false,false,null);
        for (int i = 0; i < 50; i++) {
            // 发送消息
            channel.basicPublish("","wq_queue1", null,("Hello RabbitMQ!"+i).getBytes());
            System.out.println("消息发送成功"+i);
            TimeUnit.MILLISECONDS.sleep(i * 15);
        }

        channel.close();

    }
}
